package learn.basics.innerclass;

class Body {

    class Heart {
        public void Beat() {
            System.out.println("心脏跳动");
            System.out.println("我叫：" + name_);
        }
    }

    private String name_;

    public void MethodBody() {
        System.out.println("外部类的方法");
        new Heart().Beat();
    }

    public String GetName() {
        return name_;
    }

    public void SetName(String name) {
        this.name_ = name;
    }
}

class Demo1InnerClass {
    public static void Test() {
        Body body = new Body();
        body.MethodBody();
        System.out.println("==========");

        Body.Heart heart = new Body().new Heart();
        heart.Beat();
    }
}


class Outer {
    int num_ = 10;

    public class Inner {
        int num_ = 20;

        public void MethodInner() {
            int num = 30;
            System.out.println(num);
            System.out.println(this.num_);
            System.out.println(Outer.this.num_);
        }
    }

}

class Demo2InnerClass {
    public static void Test() {
        Outer.Inner obj = new Outer().new Inner();
        obj.MethodInner();
    }
}

class MyOuter {
    public void MethodOuter() {
        final int num = 10;
        class MyInner {
            public void MethodInner() {
                System.out.println(num);
            }
        }
    }
}


class Outer2 {
    public void MethodOuter() {
        class Inner {
            int num_ = 10;

            public void MethodInner() {
                System.out.println(num_);
            }
        }

        Inner inner = new Inner();
        inner.MethodInner();
    }
}

class Demo3InnerClass {
    static void Test() {
        Outer2 o = new Outer2();
        o.MethodOuter();
    }
}


public class TestInnerClass {
    public static void main(String[] args) {
        //Demo1InnerClass.Test();
        //Demo2InnerClass.Test();
        Demo3InnerClass.Test();
    }
}
